home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / DRDOBBS.ZIP / UC993.TXT < prev    next >
Text File  |  1993-10-08  |  16KB  |  388 lines

  1. _UNDOCUMENTED CORNER_
  2. edited by Andrew Schulman
  3. written by Pete Davis
  4.  
  5. [LISTING ONE]
  6.  
  7. /* WHSTRUCT.H--Windows Help File Internal Records--Pete Davis and Ron Burk, 
  8.    June 1993. See "Undocumented Corner," DDJ, September 1993  */
  9.  
  10. typedef unsigned long   DWORD;
  11. typedef unsigned int    WORD;
  12. typedef unsigned char   BYTE;
  13.  
  14. #define HELP_MAGIC      0x00035F3FL
  15.  
  16. /* Help file Header record */
  17. typedef struct HELPHEADER {
  18.     DWORD   MagicNumber;      /* 0x00035F3F                */
  19.     long    WHIFS;            /* File offset of WHIFS header   */
  20.     long    Negative1;
  21.     long    FileSize;         /* Size of entire .HLP File  */
  22. }   HELPHEADER;
  23. /* File Header for WHIFS files */
  24. typedef struct FILEHEADER {
  25.     long    FilePlusHeader;  /* File size including this header */
  26.     long    FileSize;        /* File size not including header  */
  27.     char    TermNull;
  28. }   FILEHEADER;
  29. /* Help Directory BTREE */
  30. typedef struct WHIFSBTREEHEADER {
  31.     char    Magic[18];      /* Not exactly magic for some .MVB files   */
  32.     char    Garbage[13];
  33.     int     MustBeZero;     /* Probably shows up when Help > ~40 megs  */
  34.     int     NSplits;        /* Number of page split Btree has suffered */
  35.     int     RootPage;       /* Page # of root page                     */
  36.     int     MustBeNegOne;   /* Probably shows up when B-Tree is HUGE!! */
  37.     int     TotalPages;     /* total # to 2Kb pages in Btree           */
  38.     int     NLevels;        /* Number of levels in this Btree          */
  39.     DWORD   TotalWHIFSEntries;
  40. }   WHIFSBTREEHEADER;
  41. /* Modified B-Tree Node header to handle a pointer to the page */
  42. typedef struct BTREENODEHEADER {
  43.     WORD    Signature;      /* Signature word            */
  44.     int     NEntries;       /* Number of entries         */
  45.     int     PreviousPage;   /* Index of Previous Page    */
  46.     int     NextPage;       /* Index of Next Page        */
  47.     char    *BTData;        /* Pointer to B-Tree's data  */    
  48. }   BTREENODEHEADER;
  49. /* Modified B-Tree Index header to handle a pointer to the page */
  50. typedef struct BTREEINDEXHEADER {
  51.     WORD    Signature;      /* Signature word            */
  52.     int     NEntries;       /* Number of entries in node */
  53.     char    *IdxData;
  54. }   BTREEINDEXHEADER;
  55. /* Phrase header for uncompressed |Phrases file */
  56. typedef struct PHRASEHDR    {
  57.     int     NumPhrases;   /* Number of phrases in table                    */
  58.     WORD    OneHundred;   /* 0x0100                                        */
  59. } PHRASEHDR;
  60. /* Phrase header for compressed |Phrases file */
  61. typedef struct ALTPHRASEHDR    {
  62.     int     NumPhrases;   /* Number of phrases in table                    */
  63.     WORD    OneHundred;   /* 0x0100                                        */
  64.     long    PhrasesSize;  /* Amount of space uncompressed phrases requires */
  65. } ALTPHRASEHDR;
  66. /* Flags for |SYSTEM header Flags field below:  Unfortunately, none of these
  67.    flags are particularly solid. The 0x0004 works MOST of the time. Another
  68.    flag, 0x0008, appears both in Win32 .HLP files, and in files with Phrase
  69.    compression but without LZ77 compression. */
  70. #define NO_COMPRESSION_310      0x0000
  71. #define COMPRESSION_310         0x0004
  72. #define SYSFLAG_300             0x000A
  73. /* Header for |SYSTEM file */
  74. typedef struct SYSTEMHEADER {
  75.     BYTE    Magic;     /* 0x6C                  */
  76.     BYTE    Version;   /* Version #             */
  77.     BYTE    Revision;  /* Revision code         */
  78.     BYTE    Always0;   /* Unknown               */
  79.     WORD    Always1;   /* Always 0x0001         */
  80.     DWORD   GenDate;   /* Date/Time that the help file was generated    */
  81.     WORD    Flags;     /* Values seen: 0x0000 0x0004, 0x0008, 0x000A    */
  82.     } SYSTEMHEADER;
  83. /* Types for SYSTEMREC RecordType below:  note that other record types,
  84.    such as 0x0A, 0x0B, 0x0C, 0x0D, shown up in the large .MVB files used
  85.    by the MSDN CD-ROM and Cinemania products. */
  86. #define HPJ_TITLE       0x0001      /* Title from .HPJ file            */
  87. #define HPJ_COPYRIGHT   0x0002      /* Copyright notice from .HPJ file */
  88. #define HPJ_CONTENTS    0x0003      /* Contents=  from .HPJ            */
  89. #define MACRO_DATA      0x0004      /* RData = 4 nulls if no macros    */
  90. #define ICON_DATA       0x0005      /* Data for Icon                   */
  91. #define HPJ_SECWINDOWS  0x0006      /* Secondary window info in .HPJ   */
  92. #define HPJ_CITATION    0x0008      /* Citation= under [OPTIONS]       */
  93. /* Secondary Window Record following type 0x0006 System Record */
  94. typedef struct SECWINDOW {
  95.     WORD    Flags;          /* Flags (See Below)        */
  96.     BYTE    Type[10];       /* Type of window           */
  97.     BYTE    Name[9];        /* Window name              */
  98.     BYTE    Caption[51];    /* Caption for window       */
  99.     WORD    X;              /* X coordinate to start at */
  100.     WORD    Y;              /* Y coordinate to start at */
  101.     WORD    Width;          /* Width to create for      */
  102.     WORD    Height;         /* Height to create for     */
  103.     WORD    Maximize;       /* Maximize flag            */
  104.     BYTE    Rgb[3];         /* RGB for background       */
  105.     BYTE    Unknown1;       /* No known use             */
  106.     BYTE    RgbNsr[3];      /* RGB for non scrollable region */
  107.     BYTE    Unknown2;       /* No known use             */
  108. } SECWINDOW;
  109. /* Values for Secondary Window Flags */
  110. #define WSYSFLAG_TYPE       0x0001  /* Type is valid        */
  111. #define WSYSFLAG_NAME       0x0002  /* Name is valid        */
  112. #define WSYSFLAG_CAPTION    0x0004  /* Ccaption is valid    */
  113. #define WSYSFLAG_X          0x0008  /* X    is valid        */
  114. #define WSYSFLAG_Y          0x0010  /* Y    is valid        */
  115. #define WSYSFLAG_WIDTH      0x0020  /* Width    is valid    */
  116. #define WSYSFLAG_HEIGHT     0x0040  /* Height   is valid    */
  117. #define WSYSFLAG_MAXIMIZE   0x0080  /* Maximize is valid    */
  118. #define WSYSFLAG_RGB        0x0100  /* Rgb  is valid        */
  119. #define WSYSFLAG_RGBNSR     0x0200  /* RgbNsr   is valid    */
  120. #define WSYSFLAG_TOP        0x0400  /* On top was set in HPJ file */
  121. /* Help Compiler 3.1 System record. Multiple records possible */
  122. typedef struct SYSTEMREC {
  123.     WORD    RecordType;   /* Type of Data in record      */
  124.     WORD    DataSize;     /* Size of RData               */
  125.     char   *RData;        /* Raw data (Icon, title, etc) */
  126.     } SYSTEMREC;
  127. /* Header for |TOMAP file */
  128. typedef struct TOMAPHEADER {
  129.     long    IndexTopic;   /* Index topic for help file */
  130.     long    Reserved[15];
  131.     int     ToMapLen;     /* Number of topic pointers  */
  132.     long    *TopicPtr;    /* Pointer to all the topics */
  133.     } TOMAPHEADER;
  134.  
  135.  
  136. [LISTING TWO]
  137.  
  138. /* HELPDIR.C -- List all internal files with a Windows .HLP file. 
  139.    WHIFS = Windows Help Internal File System -- Pete Davis, June 1993
  140.    bcc helpdir.c
  141.    See "Undocumented Corner," DDJ, September 1993 */
  142. #pragma pack(1)
  143. #include <conio.h>
  144. #include <string.h>
  145. #include <stdio.h>
  146. #include <stdlib.h>
  147. #include "whstruct.h"
  148.  
  149. #define PAGE_SIZE       1024L        /* 1k pages -- must be long! */
  150.  
  151. void fail(const char *s) { puts(s); exit(1); }
  152.  
  153. int main(int argc, char *argv[]) {
  154.    HELPHEADER         HelpHdr;
  155.    WHIFSBTREEHEADER   WHIFSHdr;
  156.    BTREENODEHEADER    WHIFSNode;
  157.    int                file, aPage, c;
  158.    long               WHIFSStart, FileOffset;
  159.    FILE               *HelpFile;
  160.    
  161.    if ((HelpFile=fopen(argv[1], "rb")) == NULL)
  162.        fail("can't open file");
  163.    /* Get Help header, go to WHIFS and get WHIFS Header */
  164.    fread(&HelpHdr, sizeof(HelpHdr), 1, HelpFile);
  165.    if (HelpHdr.MagicNumber != HELP_MAGIC)
  166.        fail("not a Windows help file");
  167.    fseek(HelpFile, HelpHdr.WHIFS, SEEK_SET);
  168.    fread(&WHIFSHdr, sizeof(WHIFSHdr), 1, HelpFile);
  169.    /* WHIFS starts after the WHIFSHdr */
  170.    WHIFSStart = HelpHdr.WHIFS + sizeof(WHIFSHdr);
  171.    file=1;
  172.    /* Goto WHIFS Root */
  173.    fseek(HelpFile, WHIFSStart + (PAGE_SIZE * WHIFSHdr.RootPage), SEEK_SET);
  174.    /* Find the first leaf node */
  175.    while (file < WHIFSHdr.NLevels) {
  176.        /* if it's not a leaf, we don't need last 2 fields */
  177.        fread(&WHIFSNo